#include "audioclient.h"
#include "playlistmodel.h"
#include <QStandardItem>
#include <QFont>

PlaylistModel::PlaylistModel(AudioClient* client)
{
    setHorizontalHeaderLabels(QStringList() << "title" << "album" << "artist");
    client->setPlaylistModel(this);
    client->loadPlaylist();

    connect(client, SIGNAL(removedEntry(int)), this, SLOT(removeEntry(int)));
    connect(client, SIGNAL(playlistCleared()), this, SLOT(playlistClear()));
}

void PlaylistModel::setCurrentPosition(const unsigned int& newPosition){
    QFont newFont;
    QStandardItem *newItem;
    for (int j = 0; j < columnCount(); j++){
        newItem = item(currentPosition, j);
        newFont = newItem->font();
        newFont.setBold(false);
        newItem->setFont(newFont);

        newItem = item(newPosition, j);
        newFont = newItem->font();
        newFont.setBold(true);
        newItem->setFont(newFont);
    }
    currentPosition = newPosition;
}

void PlaylistModel::playlistClear(){
    clear();
}

void PlaylistModel::removeEntry(const int& position){
    removeRow(position);
    setHorizontalHeaderLabels(QStringList() << "title" << "album" << "artist");
}
